package com.example.demo.Controller;

import com.example.demo.Entity.Directory;
import com.example.demo.Entity.Directoryitem;
import com.example.demo.Entity.Note;
import com.example.demo.Service.DirectoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/directory")

/**
 * 目录前端操作接口
 **/
public class DirectoryController {
    @Autowired
    private DirectoryService directoryService;

    /** 查看一级目录下的所有笔记 */
    @GetMapping("/selectGroup/{group}")
    public List<Note> selectGroup(Integer group) {
        return directoryService.select(group);
    }

    /** 查看二级目录下的所有笔记 */
    @GetMapping("/selectSubGroup")
    public List<Note> selectGroup(@RequestParam Integer group, Integer subGroup) {
        return directoryService.select(group,subGroup);
    }

    /** 查看二级目录下的对应ID笔记 */
    @GetMapping("/selectSubId")
    public List<Note> selectGroup(@RequestParam Integer group,Integer subGroup,Integer subId) {
        return directoryService.select(group,subGroup,subId);
    }

    /** 更新目录 */
    @PostMapping("/update")
    public void update(@RequestBody Directory directory) {
        directoryService.update(directory);
    }

    /** 新增目录 */
    @PostMapping("/insert")
    public void insert(@RequestBody Directory directory) throws Exception {
        directoryService.insert(directory);
    }

    /** 删除一级目录（级联删除） */
    @GetMapping("deleteByGroup")
    public void delete(@RequestParam Integer group) {
        directoryService.deleteByGroup(group);
    }

    /** 删除二级目录（级联删除） */
    @GetMapping("deleteBySubGroup")
    public void delete(@RequestParam Integer group,Integer subGroup) {
        directoryService.deleteBySubGroup(group,subGroup);
    }

    /** 删除子目录 */
    @GetMapping("deleteBySubId")
    public void deleteById(@RequestParam Integer group,Integer subGroup,Integer subId) {
        directoryService.deleteBySubId(group,subGroup,subId);
    }

    /** 删除子目录 */
    @DeleteMapping("deleteByNoteId")
    public void deleteByNoteId(@RequestParam Integer noteId) {
        directoryService.deleteByNoteId(noteId);
    }

}
